#include<stdio.h>

int main(){
	int n,score=0,sign=0;
	do{
		scanf("%d",&n);
		if(n==1){
			sign=0;
			score+=1;
		}
		if(n==2){
			sign++;
			score+=sign*2;
		}
	}while(n!=0); 
	printf("%d",score);
	return 0;
} 
